import uni from '@dcloudio/vite-plugin-uni'
import { fileURLToPath, URL } from 'node:url'
import eslintPlugin from 'vite-plugin-eslint'
import ENV_CONFIG from './.env'

// https://vitejs.dev/config/
export default ({
  mode
}) => {
  return {
    plugins: [
      uni(),
      eslintPlugin({
        include: ['src/**/*.js', 'src/**/*.vue', 'src/*.js', 'src/*.vue'],
        cache: false,
        emitWarning: true,
        emitError: true
      })
    ],
    transpileDependencies: ['uview-plus'],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      },
      extensions: ['.js', '.vue', '.json']
    },
    server: {
      host: '0.0.0.0',
      port: 9528,
      open: true // 运行自动打开浏览器
    },
    define: {
      'process.env.config': ENV_CONFIG // 配置一
    }
  }
}
